$(function () {
    $("#page").load("/back/page.html");
    findAll();
});

function findAll() {
    let data = {};
    data.title = $("#title").val();
    data.pageSize = $.trim($("#pageSize").val());
    data.pageNum = $.trim($("#pageNum").val());
    data.token = $.cookie("token");
    let result = myAjax('/back/room/homeFindAll','get',data);
    showRoom(result.list);
    $("#pageCount").html(result.number);
}

function showRoom(data) {
    let html = "";//进行字符串拼接
    for (let i = 0; i < data.length; i++) {
        html += ' <tr>\n' +
            '      <td>' + data[i].id + '</td>\n"' +
            '       <td><img src="' + data[i].back + '"></td>\n' +
            '      <td>' + data[i].title + '</td>\n"' +
            '        <td><img src="' + data[i].room + '"></td>\n' +
            '        <td>' + data[i].href + '</td>\n' +
            '        <td><a  href="javascript:edit( ' + data[i].id + ')">编辑</a> <a  href="javascript:del( ' + data[i].id + ')">删除</a></td>\n' +
            '    </tr>';
    }
    $("#roomFindAll").html(html)//对当前的tbody进行赋值
}

function edit(id) {
    localStorage.setItem("id", id);
    //sessionStorage.setItem("userId",id);   本地存储  两种方式都可以
    $('#right').load('/back/room/homeEdit.html');//页面跳转
}

function del(id) {
    let result = myAjax('/back/room/homeDelete','get',{id: id,token:$.cookie("token")});
    if (result.result=== 1) {
        $("#right").load('/back/room/homeThreeRoom.html');
    } else {
        alert("删除失败")
    }
}
function homeAdd() {
    $("#right").load('/back/room/homeThreeRoomAdd.html');
}
